package scanning;

import static org.junit.Assert.assertEquals;

public class ScannerTestBase {

	private Scanner scanner;

	public void scan(String code) {
		scanner = new Scanner(code);
	}

	protected void assertNextTokenIs(TokenType expectedType, String expectedText) {
		Token t = scanner.nextToken();
		assertEquals(expectedType, t.getType());
		assertEquals(expectedText, t.getText());
	}

	protected void assertNextTokenIs(TokenType expectedType) {
		assertEquals(expectedType, scanner.nextToken().getType());
	}

	protected Token nextToken() {
		return scanner.nextToken();
	}

	protected void scanAndAssertIsOneToken(String code, TokenType type) {
		scan(code);
		assertNextTokenIs(type, code);
	}

	protected void scanFirstTokenIn(String code) {
		scan(code);
		nextToken();
	}

}